package cn.matezk.lianlian.model;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONObject;
import cn.matezk.lianlian.beans.NotifyConfig;
import lombok.Data;

import java.math.BigDecimal;
import java.util.Date;

@Data
public class Device {
    private String deviceId;
    private String productId;
    private String deviceName;
    private String version;
    private Integer poweronReason;
    private String iccid;
    private String cardSource;
    private Integer cardState;
    private Integer csq;
    private Integer switch1;
    private Integer detectState1;
    private Integer deviceStatus;
    private Date statusTime;
    private BigDecimal longitude;
    private BigDecimal latitude;
    private Integer flowPkg;
    private String familyId;
    private String roomId;
    private String aliasName;
    private NotifyConfig notifyConfig;
    private Date exFactoryTime;
    private Date expireDate;
    private Date iccidExpireDate;
    private Integer amount;
    private Date printTime;
    private JSONObject reported;

    public String getDeviceId() {
        if (ObjectUtil.isNotEmpty(deviceId))
            return deviceId;
        if (ObjectUtil.isEmpty(productId) || ObjectUtil.isEmpty(deviceName))
            return null;
        return productId.concat("/").concat(deviceName);
    }

    public static String createLockKey(String deviceId) {
        return "lock.device.".concat(deviceId);
    }

    public static Device buildCard(String cardSource, String iccid, Date iccidExpireDate)
    {
        Device device = new Device();
        device.setIccid(iccid);
        device.setCardSource(cardSource);
        device.setIccidExpireDate(iccidExpireDate);
        return device;
    }

    public String getReportedJson() {
        return ObjectUtil.isNull(reported) || reported.isEmpty() ? null : reported.toString();
    }
}
